﻿using System;
using System.Collections.Generic;

namespace Mono.Cecil
{
	// Token: 0x02000060 RID: 96
	public class DefaultAssemblyResolver : BaseAssemblyResolver
	{
		// Token: 0x0600039D RID: 925 RVA: 0x000034B5 File Offset: 0x000016B5
		public DefaultAssemblyResolver()
		{
			this.cache = new Dictionary<string, AssemblyDefinition>(StringComparer.Ordinal);
		}

		// Token: 0x0600039E RID: 926 RVA: 0x0001ADD4 File Offset: 0x00018FD4
		public override AssemblyDefinition Resolve(AssemblyNameReference name)
		{
			Mixin.CheckName(name);
			AssemblyDefinition assemblyDefinition;
			bool flag = this.cache.TryGetValue(name.FullName, out assemblyDefinition);
			AssemblyDefinition result;
			if (flag)
			{
				result = assemblyDefinition;
			}
			else
			{
				assemblyDefinition = base.Resolve(name);
				this.cache[name.FullName] = assemblyDefinition;
				result = assemblyDefinition;
			}
			return result;
		}

		// Token: 0x0600039F RID: 927 RVA: 0x0001AE24 File Offset: 0x00019024
		protected void RegisterAssembly(AssemblyDefinition assembly)
		{
			bool flag = assembly == null;
			if (flag)
			{
				throw new ArgumentNullException("assembly");
			}
			string fullName = assembly.Name.FullName;
			bool flag2 = this.cache.ContainsKey(fullName);
			if (!flag2)
			{
				this.cache[fullName] = assembly;
			}
		}

		// Token: 0x060003A0 RID: 928 RVA: 0x0001AE74 File Offset: 0x00019074
		protected override void Dispose(bool disposing)
		{
			foreach (AssemblyDefinition assemblyDefinition in this.cache.Values)
			{
				assemblyDefinition.Dispose();
			}
			this.cache.Clear();
			base.Dispose(disposing);
		}

		// Token: 0x040000E5 RID: 229
		private readonly IDictionary<string, AssemblyDefinition> cache;
	}
}
